home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Apache 1.0 / support / dbmmanage < prev    next >
Text File  |  1995-12-04  |  4KB  |  124 lines

  1. #!/usr/local/bin/perl
  2.  
  3. # ====================================================================
  4. # Copyright (c) 1995 The Apache Group.  All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. #
  10. # 1. Redistributions of source code must retain the above copyright
  11. #    notice, this list of conditions and the following disclaimer. 
  12. #
  13. # 2. Redistributions in binary form must reproduce the above copyright
  14. #    notice, this list of conditions and the following disclaimer in
  15. #    the documentation and/or other materials provided with the
  16. #    distribution.
  17. #
  18. # 3. All advertising materials mentioning features or use of this
  19. #    software must display the following acknowledgment:
  20. #    "This product includes software developed by the Apache Group
  21. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  22. #
  23. # 4. The names "Apache Server" and "Apache Group" must not be used to
  24. #    endorse or promote products derived from this software without
  25. #    prior written permission.
  26. #
  27. # 5. Redistributions of any form whatsoever must retain the following
  28. #    acknowledgment:
  29. #    "This product includes software developed by the Apache Group
  30. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  31. #
  32. # THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  33. # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35. # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  36. # IT'S CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  37. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  38. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  39. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  40. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  41. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  43. # OF THE POSSIBILITY OF SUCH DAMAGE.
  44. # ====================================================================
  45. #
  46. # This software consists of voluntary contributions made by many
  47. # individuals on behalf of the Apache Group and was originally based
  48. # on public domain software written at the National Center for
  49. # Supercomputing Applications, University of Illinois, Urbana-Champaign.
  50. # For more information on the Apache Group and the Apache HTTP server
  51. # project, please see <http://www.apache.org/>.
  52.  
  53.  
  54. # usage: dbmmanage <DBMfile> <command> <key> <value> <group>
  55. #
  56. # commands: add, delete, view, adduser
  57. #
  58. # no values needed for delete, no keys or values needed for view.
  59. # to change a value, simply use "add".
  60. # adduser encrypts the password:
  61. # dbmmanage <dbm file> adduser <person> <password>
  62. #
  63. # <group> is optional, and may also be supplied to add the user
  64. # to a specified group:
  65. # dbmmanage <dbm file> adduser <person> <password> <group>
  66.  
  67. if (scalar(@ARGV) < 2) {
  68.     print "Too few arguments.\n";
  69.     exit;
  70. }
  71.  
  72. # ugly - this should be changed to be random.
  73. $salt="XX";
  74. $file=$ARGV[0];
  75. $command=$ARGV[1];
  76. $key=$ARGV[2];
  77. $value=$ARGV[3];
  78. $group=$ARGV[4];
  79.  
  80. if ($command eq "add") {
  81.         dbmopen(%DB, $file, 0664) || die "Error: $!\n";
  82.         $value .= ":$group" if $group ne "";
  83.         $DB{$key} = $value;
  84.         dbmclose(%DB);
  85.     print "Entry $key added with value $value.\n";
  86.     exit;
  87. }
  88.  
  89. if ($command eq "adduser") {
  90.     $hash = crypt($value, "$salt");
  91.         dbmopen(%DB, $file, 0664) || die "Error: $!\n";
  92.         $hash .= ":$group" if $group ne "";
  93.         $value .= ":$group" if $group ne "";
  94.         $DB{$key} = $hash;
  95.         dbmclose(%DB);
  96.     print "User $key added with password $value, encrypted to $hash\n";
  97.     exit;
  98. }
  99.  
  100. if ($command eq "delete") {
  101.         dbmopen(%DB, $file, 0664) || die "Error: $!\n";
  102.         delete($DB{$key});
  103.         dbmclose(%DB);
  104.     exit;
  105. }
  106.  
  107. if ($command eq "view") {
  108.         dbmopen(%DB, $file, undef) || die "Error: $!\n";
  109.         $return_status = 1;
  110.         unless ($key) {
  111.                 while (($nkey,$val) = each %DB) {
  112.                         print "$nkey = $val\n";
  113.                 }
  114.         } else {
  115.                 $return_status = 0 if defined $DB{$key};
  116.                 print "$key = $DB{$key}\n";
  117.         } 
  118.         dbmclose(%DB);
  119.     exit($return_status);
  120. }
  121.  
  122. print "Command unrecognized - must be one of: view, add, adduser, delete.\n";
  123.  
  124.